﻿using System;
using System.Reflection;

namespace Taste.Internal
{
    internal class Trigger<TState, TTrigger> : ITrigger
        where TState : struct
        where TTrigger : struct
    {
        private TTrigger _triggerName;
        private StateMachine<TState, TTrigger> _stateMachine;

        public Trigger(TTrigger triggerName, StateMachine<TState, TTrigger> stateMachine)
        {
            _triggerName = triggerName;
            _stateMachine = stateMachine;
        }

        public bool CanFire(object parameter)
        {
            return _stateMachine.CanFireTrigger(_triggerName, parameter);
        }

        public void Fire(object parameter)
        {
            _stateMachine.FireTrigger(_triggerName, parameter);
        }

        public event EventHandler CanFireChanged;

        public void RaiseCanFireChanged()
        {
            if(this.CanFireChanged != null)
                this.CanFireChanged(this, EventArgs.Empty);
        }
    }
}
